import { Hero } from '/src/model/Hero';
import { Contoller } from "./Controller";
import { Card } from "./Card";
import { Store } from "./Store";

export interface PlayerOptions {
	index: number;
	camp: "ZG" | "ZC" | "FZ" | "NJ";
}
export class Player extends Contoller {
	public card: Card[] = [];
	private _hero: Hero | undefined;
	private _store: Store | undefined;

	constructor(public option: PlayerOptions) {
		super();
	}

	type() {
		return "SGS.Model.Player";
	}

	injectStore(store: Store) {
		this._store = store;
	}

	injectHero(hero: Hero) {
		this._hero = hero;
	}

	getCards(cardCount: number = 2) {
		this.card.push(...this._store?.dispatch(cardCount)!);
	}

	throwCards(cardPositions: number[]) {
		this._store?.throwCards(
			this.card.filter((_v, k) => cardPositions.includes(k))
		);
		for (let i = 0; i < this.card.length; i++) {
			if (cardPositions.includes(i)) {
				delete this.card[i];
			}
		}

		this.card = this.card.filter(v => v);
	}
}
